#include <iostream>
#include <vector>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
int n;
string s[N];

LL gcd(LL a, LL b)
{
    return b == 0 ? a : gcd(b, a % b);
}

void solve()
{
    if(n == 1)
    {
        for(int i = 0; i < s[1].size(); i++)
        {
            if(s[1][i] == '1') cout << i + 1 << endl;
            return;
        }
        cout << -1 << endl;
        return;
    }
    else
    {
        LL lcm = s[1].size() * s[2].size() / gcd(s[1].size(), s[2].size());
        for(int i = 3; i <= n; i++)
        {
            int len = s[i].size();
            lcm = len * lcm / gcd(len, lcm);
        }
        string tmp;
        while(tmp.size() < lcm) tmp += s[1];
        for(int i = 0; i < lcm; i++) 
        {
            if(tmp[i] == '1') 
            {
                int flag = true;
                for(int j = 2; j <= n; j++)
                {
                    int len = s[j].size();
                    if(s[j][i % len] == '0') 
                    {
                        flag = false;
                        break;
                    }
                }
                if(flag) 
                {
                    cout << i + 1 << endl;
                    return;
                }
            }
        }
        cout << -1 << endl;
    }
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> s[i];
    solve();
    return 0;
}